<!DOCTYPE html>
<html lang='cn' xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <title>产品列表</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport"/>
    <meta content="" name="description"/>
    <meta content="" name="author"/>
    <link th:href="@{/backend/css/bootstrap.min.css}" href="../../../static/backend/css/bootstrap.min.css"
          rel="stylesheet" type="text/css"/>
    <link th:href="@{/backend/css/bootstrap-responsive.min.css}"
          href="../../../static/backend/css/bootstrap-responsive.min.css" rel="stylesheet" type="text/css"/>
    <link th:href="@{/backend/css/font-awesome.min.css}" href="../../../static/backend/css/font-awesome.min.css"
          rel="stylesheet" type="text/css"/>
    <link th:href="@{/backend/css/style-metro.css}" href="../../../static/backend/css/style-metro.css" rel="stylesheet"
          type="text/css"/>
    <link th:href="@{/backend/css/style.css}" href="../../../static/backend/css/style.css" rel="stylesheet"
          type="text/css"/>
    <link th:href="@{/backend/css/style-responsive.css}" href="../../../static/backend/css/style-responsive.css"
          rel="stylesheet" type="text/css"/>
    <link th:href="@{/backend/css/default.css}" href="../../../static/backend/css/default.css" rel="stylesheet"
          type="text/css" id="style_color"/>
    <link th:href="@{/backend/css/uniform.default.css}" href="../../../static/backend/css/uniform.default.css"
          rel="stylesheet" type="text/css"/>
    <link th:href="@{/backend/css/pagination.css}" href="../../../static/backend/css/pagination.css" rel="stylesheet"
          type="text/css"/>
    <link rel="shortcut icon" th:href="@{/backend/images/favicon.ico}"
          href="../../../static/backend/images/favicon.ico"/>
    <link href="../../../static/backend/css/Pager.css" th:href="@{/backend/css/Pager.css}" rel="stylesheet"
          type="text/css"/>
</head>

<body>
<div class="container-fluid">
    <div class="row-fluid">
        <h3 class="page-title"><i class="fa fa-shopping-bag"></i> 产品管理</h3>
        <ul class="breadcrumb">
            <li>
                <a href="#"><i class="fa fa-home"></i>产品管理</a>
                <i class="fa fa-angle-right"></i>
            </li>
            <li>
                <a href="#">产品列表</a>
            </li>
        </ul>
    </div>
    <div class="row-fluid">
        <div class="portlet">
            <div class="portlet-title">
                <div class="caption">
                    <i class="fa fa-reorder"></i>
                    产品列表
                </div>
                <div class="tools">
                    <button onclick="window.location.href='/fleastreet/manager/product/add';" class="btn mini"><i class="fa fa-plus"></i>添加
                    </button>
                </div>
            </div>
            <div class="portlet-body">
                <table id="productTable" class="table table-advance table-hover">
                    <thead>
                    <tr>
                        <th>编号</th>
                        <th>产品图片</th>
                        <th>产品名称</th>
                        <th>产品价格</th>
                        <th>产品子类</th>
                        <th>库存</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>

                    </tbody>
                </table>
                <!--<div id="Pagination" class="pagination align_right">&lt;!&ndash; 这里显示分页 &ndash;&gt;</div>-->
                <div id="pager"></div>
                <!--by linmm 前端分页具体实现,参考http://www.jq22.com/jquery-info3967-->
            </div>
        </div>
    </div>
</div>

<script th:src="@{/backend/js/jquery-1.10.1.min.js}" src="../../../static/backend/js/jquery-1.10.1.min.js"
        type="text/javascript"></script>
<script src="../../../static/frontend/layer/layer.js" th:src="@{/frontend/layer/layer.js}"></script>
<script th:src="@{/backend/js/jquery-migrate-1.2.1.min.js}" src="../../../static/backend/js/jquery-migrate-1.2.1.min.js"
        type="text/javascript"></script>
<!-- IMPORTANT! Load jquery-ui-1.10.1.custom.min.js before bootstrap.min.js to fix bootstrap tooltip conflict with jquery ui tooltip -->
<script th:src="@{/backend/js/jquery-ui-1.10.1.custom.min.js}"
        src="../../../static/backend/js/jquery-ui-1.10.1.custom.min.js" type="text/javascript"></script>
<script th:src="@{/backend/js/bootstrap.min.js}" src="../../../static/backend/js/bootstrap.min.js"
        type="text/javascript"></script>
<script th:src="@{/backend/js/jquery.slimscroll.min.js}" src="../../../static/backend/js/jquery.slimscroll.min.js"
        type="text/javascript"></script>
<script th:src="@{/backend/js/jquery.blockui.min.js}" src="../../../static/backend/js/jquery.blockui.min.js"
        type="text/javascript"></script>
<script th:src="@{/backend/js/jquery.cookie.min.js}" src="../../../static/backend/js/jquery.cookie.min.js"
        type="text/javascript"></script>
<script th:src="@{/backend/js/jquery.uniform.min.js}" src="../../../static/backend/js/jquery.uniform.min.js"
        type="text/javascript"></script>
<script th:src="@{/backend/js/app.js}" src="../../../static/backend/js/app.js" type="text/javascript"></script>
<script th:src="@{/backend/js/jquery.pagination.js}" src="../../../static/backend/js/jquery.pagination.js"
        type="text/javascript"></script>
<script src="../../../static/backend/js/jquery.pager.js" th:src="@{/backend/js/jquery.pager.js}"
        type="text/javascript"></script>
<script th:inline="javascript" type="text/javascript">

    //		<![CDATA[
    //    var msg = [[${message}]];
    //    if (msg) {
    //        layer.msg(msg);
    //    }

    function edit(id) {
        window.location.href = "/fleastreet/manager/product/edit/" + id;
    }

    function del(id, btn) {
        if (!confirm("是否删除id为" + id + "的产品？")) {
            return;
        }
        $.ajax({
            url: "/fleastreet/manager/product/del/" + id,
            type: "get",
            success: function (result) {
                if (result.code == 0) {
                    if (result.data == true) {
                        layer.msg("删除成功！");
                        $(btn).parent().parent().fadeOut();
                    } else {
                        layer.msg("删除失败！");
                    }
                } else {
                    layer.msg(result.msg);
                }
            }
        });
    }
    //获取所有产品入口
    var pagetotal;
    var pageSize = 7;
    $(function () {
                $.ajax({
                    url: "/fleastreet/manager/product/total",
                    type: "get",

                    success: function (result) {
                        if (result.code == 0) {
                            pagetotal = Math.ceil(result.data / pageSize);
                            $("#pager").pager({pagenumber: 1, pagecount: pagetotal, buttonClickCallback: PageClick});
                        } else {
                            layer.msg("获取product/total失败：" + result.msg);
                        }
                    }
                });
            },
            PageClick(1));


    function PageClick(pageclickednumber) {
        $("#pager").pager({pagenumber: pageclickednumber, pagecount: pagetotal, buttonClickCallback: PageClick});
        $.ajax({
            type: "post",
            //分页查询，每页7个
            url: "/fleastreet/manager/product/list/" + pageclickednumber,
            success: function (result) {
                if (result.code == 0) {
                    showList(result.data);
                } else {
                    layer.msg("获取product/list失败：" + result.msg);
                }
            }
        });
    }

    function showList(data) {
        if (!data || !data.length > 0) {
            return;
        }
        //清空表
        var tbody = $("#productTable tbody").eq(0);
        tbody.html("");
        for (var i = 0; i < data.length; i++) {
            var tr = $("<tr style='display:none;height:50px;'></tr>");
            tr.append($("<td></td>").text(data[i].productId));
            var src = "/fleastreet/manager/product/img/" + data[i].productId;//图片路径
            tr.append($("<td></td>").html("<img style='display: block;height: 50px;max-width: 100%;' src='" + src + "'/>"
            ))
            ;
            tr.append($("<td></td>").text(data[i].name));
            tr.append($("<td></td>").text("￥" + data[i].price));
//            if (1 == data[i].isHot)
//                tr.append($("<td></td>").html("<b style='color:red;'>是</b>"));
//            else
//                tr.append($("<td></td>").html("否"));
            tr.append($("<td></td>").text(data[i].productTypeId));
            tr.append($("<td></td>").text(data[i].number));
            tr.append($("<td></td>")
                    .append($('<button style="margin-right:20px;" class="btn mini green" onclick="edit(' + data[i].productId + ')"><i class="fa fa-edit"></i> 编辑</button>'))
                    .append($('<button class="btn mini red" onclick="del(' + data[i].productId + ',this)"><i class="fa fa-trash"></i> 删除</button>')));
            tbody.append(tr);
            tr.fadeIn();
        }

    }
    //    $(document).ready(function() {
    //        $("#pager").pager({ pagenumber: 1, pagecount: 2, buttonClickCallback: PageClick });
    //    });
    //
    //    PageClick = function(pageclickednumber) {
    //        $("#pager").pager({ pagenumber: pageclickednumber, pagecount: 2, buttonClickCallback: PageClick });
    //        $("#result").html("Clicked Page " + pageclickednumber);
    //    }
    //		]]>
</script>
</body>

</html>